package com.wlyuan.open.constants;

import lombok.Getter;

import java.util.Arrays;
import java.util.Map;
import java.util.Optional;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * @author lijing
 * 运输方式
 */
@Getter
public enum ShippingMode {

    TRUCK("货车", 1),
    AIRPLANE("飞机", 2),
    RAIN("火车", 3),
    SHIPPING("轮船", 4),
    ;

    private final String name;
    private final Integer value;

    ShippingMode(String name, Integer value) {
        this.value = value;
        this.name = name;
    }

    private static final Map<Integer, ShippingMode> MAP = Arrays.asList(ShippingMode.values()).stream().collect(Collectors.toMap(ShippingMode::getValue, Function.identity()));

    public static ShippingMode fromValue(Integer value) {
        return Optional.ofNullable(value).map(a -> Optional.ofNullable(MAP.get(a)).orElse(null)).orElse(null);
    }
}
